package com.sb.framework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class RbCalenderUtil {

	/**
	 * 获取一个月份的第一天日期
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public static String getFirstDayOfMonth(int year, int month) {
		Calendar cal = Calendar.getInstance();
		// 设置年份
		cal.set( Calendar.YEAR, year );
		// 设置月份
		cal.set( Calendar.MONTH, month - 1 );
		// 设置日历中月份的第1天
		cal.set( Calendar.DAY_OF_MONTH, 1 );
		// 格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
		String firstDayOfMonth = sdf.format( cal.getTime() );

		return firstDayOfMonth;
	}

	/**
	 * 获得指定日期的后三天(t+3)
	 * 
	 * @param specifiedDay
	 * @return
	 */
	public static String getSpecifiedDayAfter(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat( "yy-MM-dd" ).parse( specifiedDay );
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime( date );
		int day = c.get( Calendar.DATE );
		c.set( Calendar.DATE, day + 3 );
		String dayAfter = new SimpleDateFormat( "yyyy-MM-dd" ).format( c.getTime() );
		return dayAfter;
	}

	/**
	 * 获得指定日期的前三天(t+3)
	 * 
	 * @param specifiedDay
	 * @return
	 */
	public static String getSpecifiedDayBegin(String specifiedDay) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat( "yy-MM-dd" ).parse( specifiedDay );
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime( date );
		int day = c.get( Calendar.DATE );
		c.set( Calendar.DATE, day - 3 );
		String dayAfter = new SimpleDateFormat( "yyyy-MM-dd" ).format( c.getTime() );
		return dayAfter;
	}
}
